package com.hison.tandainbao.controller;

import com.hison.tandainbao.entiy.pojo.domain.TbItems;
import com.hison.tandainbao.response.ResponseResult;
import com.hison.tandainbao.service.TbItemsService;
import com.hison.tandainbao.service.TbJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: ShopItemsController
 * @Descripiton: 失物招领  寻物启事 控制类
 * @Author: 小郑
 * @Date： 2024/3/30 16:47
 * @Version：1.8
 **/
@RestController
@RequestMapping("/shopItem")
@Api(value ="失物招领(寻物启事)控制类",tags = "失物招领(寻物启事)控制类")
public class ShopItemsController {

    @Autowired
    private TbItemsService tbItemsService;


    /**
     * 全部获取
     *
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/30
     * @see ResponseResult
     * @since version
     *///失物招领相关
    //1.获取所有的失物招领寻物启示信息
    @GetMapping("getAll")
    @ApiOperation(value = "获取所有的失物招领寻物启示信息",produces = "application/json",httpMethod = "GET")
    public ResponseResult getAll(){
        return  tbItemsService.getAll();
    }

    /**
     * 添加项目
     *
     * @param tbItems 结核病项目
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/30
     * @see TbItems
     * @see ResponseResult
     * @since version
     *///发布信息
    @PostMapping("/addItem")
    @ApiOperation(value = "添加寻主物品信息,前端提供 类别选项",produces = "application/json",httpMethod = "POST")
    public ResponseResult addItem(@RequestBody TbItems tbItems){
        return  tbItemsService.addItem(tbItems);
    }

    /**
     * 获取我放物
     *
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/30
     * @see ResponseResult
     * @since version
     *///浏览自己发布的物品
    @GetMapping("/getMyPutItems")
    @ApiOperation(value = "获取自己发布的物品信息",produces = "application/json",httpMethod = "GET")
    public ResponseResult getMyPutItems(){
        return  tbItemsService.getMyPutItems();
    }

    /**
     * 获取项目
     *
     * @param name 名字
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/30
     * @see String
     * @see ResponseResult
     * @since version
     *///4.根据名字搜索
    @GetMapping("/getItems/{name}")
    @ApiOperation(value = "根据名称模糊查询信息",produces = "application/json",httpMethod = "GET")
    public  ResponseResult getItem(@PathVariable("name") String   name){
        return  tbItemsService.getItem(name);
    }

    /**
     * 更新项目
     *
     * @param itemId 商品 ID
     * @param type   类型
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/30
     * @see String
     * @see Integer
     * @see ResponseResult
     * @since version
     *///修改自己发布的
    @PutMapping("/updateMyItem")
    @ApiOperation(value = "修改自己发布的物品信息",produces = "application/json",httpMethod = "PUT")
    public ResponseResult updateItem(@RequestParam("itemId") Integer itemId,@RequestParam("type") Integer type){
        return  tbItemsService.updateItem(itemId,type);
    }

    //删除自己发布的
    @DeleteMapping("/delItems/{ItemId}")
    @ApiOperation(value = "根据ID删除信息",produces = "application/json",httpMethod = "DELETE")
    public  ResponseResult  deleteItem(@PathVariable("ItemId") Integer ItemId){
        return  tbItemsService.deleteItem(ItemId);
    }

    //----------------------------  管理员  ------------------------------------

    //1. 审核
    @PutMapping("/adminUpdateStatus")
    @ApiOperation(value = "管理员审核物品信息",produces = "application/json",httpMethod = "PUT")
    public  ResponseResult  adminUpdateStatus(@RequestParam("itemId") Integer  itemId, @RequestParam("status") Integer status){
        return tbItemsService.adminUpdateStatus(itemId, status);
    }

    //2.管理员删除
    @DeleteMapping("/deleteItemByAdmin/{ItemId}")
    @ApiOperation(value = "管理员删除物品信息",produces ="application/json",httpMethod = "DELETE")
    public ResponseResult deleteItemByAdmin(@ApiParam(value = "ItemId") Integer itemId){
        return  tbItemsService.deleteItem(itemId);
    }

    //管理员获取所有的发布信息
    @GetMapping("/adminGetAll")
    @ApiOperation(value = "管理员获取所有的信息",produces = "application/json",httpMethod = "GET")
    public  ResponseResult  adminGetAll(@RequestParam(value = "current", defaultValue = "1") Integer current, @RequestParam(value = "total",defaultValue = "10" ) Integer total){
        return  tbItemsService.adminGetAll(current,total);
    }
}